/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package py.com.peluq.model.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Diego_M
 */
@Entity
@Table(name = "stock", catalog = "peludb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Stock.findAll", query = "SELECT s FROM Stock s"),
    @NamedQuery(name = "Stock.findByIddeposito", query = "SELECT s FROM Stock s WHERE s.stockPK.iddeposito = :iddeposito"),
    @NamedQuery(name = "Stock.findByIdseccion", query = "SELECT s FROM Stock s WHERE s.stockPK.idseccion = :idseccion"),
    @NamedQuery(name = "Stock.findByIdsucursal", query = "SELECT s FROM Stock s WHERE s.stockPK.idsucursal = :idsucursal"),
    @NamedQuery(name = "Stock.findByProdCod", query = "SELECT s FROM Stock s WHERE s.stockPK.prodCod = :prodCod"),
    @NamedQuery(name = "Stock.findByCantidad", query = "SELECT s FROM Stock s WHERE s.cantidad = :cantidad")})
public class Stock implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected StockPK stockPK;
    @Column(name = "cantidad")
    private Integer cantidad;
    @JoinColumn(name = "prod_cod", referencedColumnName = "prod_cod", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Productos productos;
    @JoinColumn(name = "idsucursal", referencedColumnName = "idsucursal", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Sucursal sucursal;
    @JoinColumns({
        @JoinColumn(name = "idseccion", referencedColumnName = "idseccion", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "iddeposito", referencedColumnName = "iddeposito", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "idsucursal", referencedColumnName = "idsucursal", nullable = false, insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Seccion seccion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "stock")
    private Collection<Ajuste> ajusteCollection;

    public Stock() {
    }

    public Stock(StockPK stockPK) {
        this.stockPK = stockPK;
    }

    public Stock(int iddeposito, int idseccion, int idsucursal, int prodCod) {
        this.stockPK = new StockPK(iddeposito, idseccion, idsucursal, prodCod);
    }

    public StockPK getStockPK() {
        return stockPK;
    }

    public void setStockPK(StockPK stockPK) {
        this.stockPK = stockPK;
    }

    public Integer getCantidad() {
        return cantidad;
    }

    public void setCantidad(Integer cantidad) {
        this.cantidad = cantidad;
    }

    public Productos getProductos() {
        return productos;
    }

    public void setProductos(Productos productos) {
        this.productos = productos;
    }

    public Sucursal getSucursal() {
        return sucursal;
    }

    public void setSucursal(Sucursal sucursal) {
        this.sucursal = sucursal;
    }

    public Seccion getSeccion() {
        return seccion;
    }

    public void setSeccion(Seccion seccion) {
        this.seccion = seccion;
    }

    @XmlTransient
    public Collection<Ajuste> getAjusteCollection() {
        return ajusteCollection;
    }

    public void setAjusteCollection(Collection<Ajuste> ajusteCollection) {
        this.ajusteCollection = ajusteCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (stockPK != null ? stockPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Stock)) {
            return false;
        }
        Stock other = (Stock) object;
        if ((this.stockPK == null && other.stockPK != null) || (this.stockPK != null && !this.stockPK.equals(other.stockPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "py.com.peluq.model.entity.Stock[ stockPK=" + stockPK + " ]";
    }
    
}
